package com.wg.utils;

import org.springframework.beans.BeanUtils;

import java.util.List;
import java.util.stream.Collectors;

public class WgUtil {
    private WgUtil() {

    }

    public static <T> T copyObject(Object source, Class<T> clazz) {
        T target = null;
        try {
            target = clazz.newInstance();
            BeanUtils.copyProperties(source, target);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return target;
    }

    public static <V, T> List<T> copyObjectList(List<V> sources, Class<T> clazz) {
        return sources.stream().map(item -> copyObject(item, clazz)).collect(Collectors.toList());
    }
}
